import { usePageRequest, useRequest } from "../../../utils/request";
import dayjs from "../../../utils/day";

Component({
    properties: {},
    data: {
        reData: null,
        inputValue: ''
    },
    methods: {
        onLoad(options) {
            this.setData({
                id: options.id
            })
            this.request = new usePageRequest('api/housecommentlist', {
                params: {
                    house_id: options.id
                },
                pretreatment: data => {
                    data.list = data.list.map(item => {
                        item.public_time = dayjs.unix(item.public_time).format('YYYY-MM-DD')
                        item.imgs = item.imgs.map(img => {
                            return { url: img }
                        })
                        item.reply = item.reply.map(reply => {
                            reply.public_time = dayjs.unix(reply.public_time).format('YYYY-MM-DD')
                            return reply
                        })
                        return item
                    })
                    return data
                }
            }, this)
            this.reRequest = new useRequest('api/ownerreplyusertalk', { hold: true }, this)
        },
        re(e) {
            this.setData({
                reData: e.currentTarget.dataset.data
            })
        },
        submit() {
            if (this.data.inputValue) {
                this.reRequest.run({
                    comment_no: this.data.reData.comment_id,
                    description: this.data.inputValue
                }).then(() => {
                    this.setData({
                        reData: null,
                        inputValue: ''
                    })
                })
            }
        },
        c(){

        }
    }
});
